home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8029 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  43 lines

  1. Path: news.iastate.edu!usenet
  2. From: Steve Lee <sjlee@iastate.edu>
  3. Newsgroups: comp.lang.c++
  4. Subject: Static Member Functions
  5. Date: Sun, 18 Feb 1996 11:30:46 -0800
  6. Organization: Iowa State University
  7. Message-ID: <31277E66.687F@iastate.edu>
  8. NNTP-Posting-Host: dial47.ppp.iastate.edu
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0b6b (Win16; I)
  13.  
  14. Hi,
  15.  
  16. I have a couple of questions about static member functions.
  17.  
  18. 1)  I was wondering why C++ doesn't provide (or maybe it does and I don't) a way to protect a 
  19. static member function by making it constant.  What I had in mind was something like the usage of 
  20. const for a member function.  I know that in this sense, it is making the implicit variable *this 
  21. constant, and that static member functions don't have an implicit *this variable since they don't 
  22. act on a specific object.  I want to know why this, or something similar isn't possible.
  23.  
  24. class foo {
  25.  
  26.   static int GetCount() const;
  27.   static int count;
  28. };
  29.  
  30. 2)  In the example above, count is private.  I find it interesting though that any piece of code 
  31. can initialize the private variable count.  Isn't this contradictory?  The only thing I can think 
  32. of is that the linker only allows it to be initialized once (obviously), and if the implementor 
  33. of the class initializes it, then no users will be able to without a linker error.
  34.  
  35. Thanks in advance.
  36.  
  37. -- 
  38. Steve Lee
  39. Computer Engineering/Computer Science
  40. Iowa State University
  41. email -> sjlee@iastate.edu
  42. WWW   -> http://www.cs.iastate.edu/~sjlee/homepage.html
  43.